// 页面路径：store/index.js 
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex); //vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state: { //存放状态
		shopinfo: uni.getStorageSync('shopinfo') ? JSON.parse(uni.getStorageSync('shopinfo')) : '',
		shop_token: uni.getStorageSync('shop_token') ? uni.getStorageSync('shop_token') : '',
		shop_id: uni.getStorageSync('shop_id') ? uni.getStorageSync('shop_id'): '',
		lang: uni.getStorageSync('lang') ? uni.getStorageSync('lang') : 'cn',
			location: '',
			address: '',
			ugaddress:'',
			shop:{
				totalprice:0,
				totalnumber:0,
				totalshop:[]
			},
			keyboard:false
	},
	getters: {
		getuserinfo(state) {
			return state.shopinfo
		},
		gettoken(state) {
			return state.shop_token
		},
		getlocation(state) {
			return state.location
		},
		getaddress(state) {
			return state.address
		},
		getugaddress(state) {
			return state.ugaddress
		},
		getshop_id(state){
			return state.shop_id
		}
	},
	mutations: {
		//键盘监听--H5键盘有问题
		setKeyboard(state,keyboard){
			state.keyboard = keyboard;
		},
		//用户信息
		setUserinfo(state, e) {
			uni.setStorageSync('shopinfo', JSON.stringify(e))
			state.shopinfo = e;
		},
		//token
		setUsertoken(state, e) {
			uni.setStorageSync('shop_token', e)
			state.shop_token = e;
		},
		//语言
		setLang(state, lang) {
			uni.setStorageSync('lang', lang)
			state.lang = lang;
				// postlang({
				// 	language: lang == 'ug' ? 'ug' : 'zh_CN'
				// }).then((res) => {
				// 	if (res.code == 200) {
				// 	}
				// })
		},
		//地址
		setLocation(state, location) {
			state.location = location;
		},
		//地址
		setAddress(state, address) {
			state.address = address;
		},
		//维吾尔语地址
		setugAddress(state, ugaddress) {
			state.ugaddress = ugaddress;
		},
		//setSopid
		setSopid(state,id){
			uni.setStorageSync('shop_id', id)
			state.shop_id=id;
		}
	}
})
export default store